package com.bob.idea.gui.action;

import com.bob.common.DataStore;
import com.bob.idea.common.Constant;

import javax.swing.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.HashSet;
import java.util.Set;

public class CheckBoxActionListener implements ItemListener {

    @Override
    public void itemStateChanged(ItemEvent e) {
        System.out.println(" ========================");
        if(!DataStore.getDataStore().getData().containsKey(Constant.CACHE_KEY_Selectd)){
            DataStore.getDataStore().getData().put(Constant.CACHE_KEY_Selectd,new HashSet<String>());
        }
        Set<String> o = (HashSet)DataStore.getDataStore().getData().get(Constant.CACHE_KEY_Selectd);
        JCheckBox item = (JCheckBox)e.getSource();
        if (item.isSelected()){
            o.add(item.getName());
        }else {
            o.remove(item.getName());
        }
        System.out.println(o.toString());
    }

}
